<?php 
namespace App\Infra\User;

use App\Models\Weight;
use App\Utils\ModelSDK\ModelOperator;
use DB;

class WeightManage{

	use ModelOperator;

	public function createWeight($data){
		$this->create(Weight::class,$data);
	}

	public function getRecordById($id){
		return Weight::find($id);
	}

	public function getWeights($conditions){
		return $this->findModel(Weight::class,Weight::query()->orderBy('created_at','DESC'),$conditions,true);
	}

	public function getRecordToDay($conditions){
		return DB::select(Weight::$SQL_SELECT_TODAY,[$conditions['wechat_user_id']]);
	}

	public function getRecordToDayAndId($conditions){
		return DB::select(Weight::$SQL_SELECT_ID_AND_TODAY,[$conditions['id'],$conditions['wechat_user_id']]);
	}

	public function updateRecord($id,$data){
		$this->update(Weight::class,$id,$data);
	}

}